<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>The payload - Boost.Outcome documentation</title>
<link rel="stylesheet" href="../../css/boost.css" type="text/css">
<meta name="generator" content="Hugo 0.52 with Boostdoc theme">
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>

<link rel="icon" href="../../images/favicon.ico" type="image/ico"/>
<body><div class="spirit-nav">
<a accesskey="p" href="../../experimental/worked-example/preamble.html"><img src="../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../experimental/worked-example.html"><img src="../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../experimental/worked-example/constructor.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
  <div class="titlepage"><div><div><h1 style="clear: both">The payload</h1></div></div></div>
  <p>We define the code domain&rsquo;s <code>value_type</code> &ndash; the payload to be transported by
status codes using this code domain &ndash; to be a POSIX <code>errno</code> value, an integer
line number and a const char pointer.</p>

<div class="code-snippet"><div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="k">public</span><span class="o">:</span>
  <span class="c1">// This is the value type for `file_io_error`. We add line number and source file path.
</span><span class="c1"></span>  <span class="k">struct</span> <span class="n">value_type</span>
  <span class="p">{</span>
    <span class="k">typename</span> <span class="n">outcome_e</span><span class="o">::</span><span class="n">posix_code</span><span class="o">::</span><span class="n">value_type</span> <span class="n">errcode</span><span class="p">;</span>  <span class="c1">// from POSIX, as we inherit from _posix_code_domain
</span><span class="c1"></span>
    <span class="c1">// Our additional payload
</span><span class="c1"></span>    <span class="kt">int</span> <span class="n">lineno</span><span class="p">;</span>        <span class="c1">// from __LINE__
</span><span class="c1"></span>    <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">file</span><span class="p">;</span>  <span class="c1">// from __FILE__
</span><span class="c1"></span>    <span class="c1">// Could also place a backtrace of void *[16] here ...
</span><span class="c1"></span>  <span class="p">};</span>
</code></pre></div><a href="https://github.com/boostorg/outcome/tree/master/doc/src/snippets/experimental_status_code.cpp#L83" class="code-snippet-url" target="_blank">View this code on Github</a></div>


<p>You will note that this is a <code>TriviallyCopyable</code> type, and so gains an implicit
conversion to any <code>status_code&lt;erased&lt;T&gt;&gt;</code> where <code>sizeof(T) &gt;= sizeof(value_type)</code>.</p>

<p><code>error</code> is however <code>status_code&lt;erased&lt;intptr_t&gt;&gt;</code>, and <code>sizeof(intptr_t) &lt; sizeof(value_type)</code>,
so it is not possible to implicitly convert status codes from this domain into
<code>error</code>. Instead, you must tell the compiler how to do the conversion, as we
shall see later.</p>


        </div><p><small>Last revised: January 26, 2019 at 23:38:56 UTC</small></p>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../experimental/worked-example/preamble.html"><img src="../../images/prev.png" alt="Prev"></a>
    <a accesskey="u" href="../../experimental/worked-example.html"><img src="../../images/up.png" alt="Up"></a>
    <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../experimental/worked-example/constructor.html"><img src="../../images/next.png" alt="Next"></a></div></body>
</html>
